#include <iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
map<string,vector<string> > mp;
int main()
{
//	freopen("data.txt","r",stdin); 
  int N;cin>>N;
  vector<string> theName;
  for(int i=0;i<N;i++){
    string no;cin>>no;string name;cin>>name;
    mp[name].push_back(no);
    theName.push_back(name);
  }

  for(int i=0;i<theName.size();i++){
    cout<<theName[i]<<" "<<mp[theName[i]].size()<<endl;;
    for(int j=0;j<mp[theName[i]].size();j++)
      cout<<mp[theName[i]][j]<<endl;
  }

  return 0;
}
